package com.fz.us.admin.base.bean.search.result;

import com.fz.us.admin.base.bean.search.Search;
import org.springframework.util.Assert;

import java.util.List;

/**
 * 查询 - 结果 - SearchResultPaging
 * ============================================================================
 * 版权所有 2016 。
 *
 * @author fallenpanda
 * @version 1.0 2016-07-13 。
 * ============================================================================
 */
public class SearchResultPaging extends SearchResultList {

    private final Integer pageNumber;
    private final Integer pageSize;
    private final Long totalCount;
    private final Long pageCount;

    public Integer getPageNumber() {
        return pageNumber;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public Long getTotalCount() {
        return totalCount;
    }

    public Long getPageCount() {
        return pageCount;
    }

    private SearchResultPaging(Search search, List list, Integer pageNumber, Integer pageSize, Long totalCount, Long pageCount) {
        super(search, list);
        this.pageNumber = pageNumber;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.pageCount = pageCount;
    }

    public static SearchResultPaging list(Search search, Integer pageNumber, Integer pageSize, Long totalCount, Long pageCount, List list) {
        return newBuilder().setSearch(search).setPageNumber(pageNumber).setPageSize(pageSize).setTotalCount(totalCount).setPageCount(pageCount).setList(list).build();
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public static class Builder extends SearchResultList.Builder {

        private Integer pageNumber;
        private Integer pageSize;
        private Long totalCount;
        private Long pageCount;

        @Override
        protected Builder getThis() {
            return this;
        }

        @Override
        public Builder setSearch(Search search) {
            this.search = search;
            return this;
        }

        public Builder setPageNumber(Integer pageNumber) {
            this.pageNumber = pageNumber;
            return this;
        }

        public Builder setPageSize(Integer pageSize) {
            this.pageSize = pageSize;
            return this;
        }

        public Builder setTotalCount(Long totalCount) {
            this.totalCount = totalCount;
            return this;
        }

        public Builder setPageCount(long pageCount) {
            this.pageCount = pageCount;
            return this;
        }

        public Builder setList(List list) {
            this.list = list;
            return this;
        }

        @Override
        public SearchResultPaging build() {
            Assert.notNull(search, "search 不能为空");
         //   Assert.isTrue(pageNumber >= 0, "totalCount 必须大于等于 0");
         //   Assert.isTrue(pageSize > 0, "pageCount 必须大于 0");
          //  Assert.isTrue(totalCount >= 0, "totalCount 必须大于等于 0");
          //  Assert.isTrue(pageCount >= 0, "pageCount 必须大于等于 0");
            Assert.notNull(list, "list 不能为空");
            return new SearchResultPaging(search, list, pageNumber, pageSize, totalCount, pageCount);
        }

    }

}
